#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QAction>
#include "dataframe.h"
#include <QModelIndexList>
#include <atomic>
#include <thread>
#include <future>
#include "dataservers.h"
#include <QMap>

#define DELETE(p) delete p;
#define SAFE_DEETE(p) if(p) DELETE(p)

#define SAFE_DELETE_FILE(pFile) \
    if(pFile){\
        pFile->close();\
        DELETE(pFile)\
    }

const QString g_prefixNotUsedData = "not_used_table_";
const QString g_prefixUsedData = "used_table_";
const int g_location = 4;
const QString g_dbName = "test.db";
const QString g_SqlCreateTemplate = "CREATE TABLE IF NOT EXISTS %1%2(phone varchar(32) not null)";
const QString g_SqlInsertTempate = "INSERT INTO %1%2(phone) VALUES(?)";

extern QMap<QString, bool> g_mapDatabaseTables;

enum QueryType{
    LIKE = 0
};

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    QMenu   *fileMenu;
    QAction  *loadfileA;
    std::atomic_bool loadFlagA;
    std::future<void> linesA;
    QAction  *loadfileB;
    std::atomic_bool loadFlagB;
    std::future<QVariantList> linesB;

    DataServers* ds;

    DataFrame dfA;
    DataFrame dfB;
private slots:
    void loadA(bool);
    void loadB(bool);

    void QueryAndOutPutNumberField(bool);
};


/**
 * @brief GetFileDataProcessThread
 * @param loadFlag  隔离加载文件
 * @param dfA   文件数据格式
 * @param updateStatus  状态更新函数
 * @param firstStatus  开始加载前的状态
 * @param secondStatus  数据加载完成的状态
 * @param thirdStatus   数据导入中的状态
 * @param lastStatus    数据导入完成的状态
 * @return  返回这个创建的线程
 */

std::thread GetFileDataProcessThread(std::atomic_bool* loadFlag
                                            , DataFrame dfA
                                            , std::function<void(const QString&)> updateStatus
                                            , const QString& firstStatus
                                            , const QString& secondStatus
                                            , const QString& thirdStatus
                                            , const QString& lastStatus
                                            , const QString& prefixTable = g_prefixUsedData
                                            , const QString& sqlCreateTemplate = g_SqlCreateTemplate
                                            , const QString& sqlInsertTempate = g_SqlInsertTempate
                                     );
#endif // MAINWINDOW_H
